<template>
  <div class="login">
    <div class="register">
      <img src="../assets/images/register.png"/>
    </div>
    <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
      <div class="back" @click="goback()">返回</div>
      <h3 class="title">学员注册</h3>
      <div class="flex_row">
        <div class="reg_title">学员姓名：</div> 
        <el-form-item>
          <el-input v-model="username" type="text" style="width: 140%;" auto-complete="off" placeholder="请输入学员姓名">
          </el-input>
        </el-form-item>
      </div>
      <div class="flex_row">
        <div class="reg_title">用户性别：</div>
        <el-form-item>
          <el-select v-model="sex" placeholder="请选择用户性别" class="search_info">
            <el-option
              v-for="item in sexList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </div>
      <div class="flex_row">
        <div class="reg_title">手机号：</div> 
        <el-form-item>
          <el-input v-model="phonenumber" type="text" style="width: 140%;" auto-complete="off" placeholder="请输入手机号">
          </el-input>
        </el-form-item>
      </div>
      <div class="flex_row">
        <div class="reg_title">身份证号：</div> 
        <el-form-item>
          <el-input v-model="identificationCard" type="text" style="width: 140%;" auto-complete="off" placeholder="请输入身份证号">
          </el-input>
        </el-form-item>
      </div>
      <div class="flex_row">
        <div class="reg_title">学历：</div>
        <el-form-item>
          <el-select v-model="education" placeholder="请选择学历" class="search_info">
            <el-option
              v-for="item in educationList"
              :key="item.key"
              :label="item.value"
              :value="item.key"
            ></el-option>
          </el-select>
        </el-form-item>
      </div>
      <div class="flex_row">
        <div class="reg_title">工作单位：</div> 
        <el-form-item>
          <el-input v-model="work" type="text" style="width: 140%;" auto-complete="off" placeholder="请输入工作单位">
          </el-input>
        </el-form-item>
      </div>
      <div class="flex_row">
        <div class="reg_title">报考级别：</div> 
        <el-form-item>
          <el-select v-model="testLevel" placeholder="请选择报考级别" class="search_info">
            <el-option
              v-for="item in levelList"
              :key="item.key"
              :label="item.value"
              :value="item.key"
            ></el-option>
          </el-select>
          <!-- <el-input v-model="testLevel" type="text" style="width: 140%;" auto-complete="off" placeholder="请输入报考级别">
          </el-input> -->
        </el-form-item>
      </div>
      <div class="flex_row">
        <div class="reg_title">报考方向：</div> 
        <el-form-item>
          <el-select v-model="testDirection" placeholder="请选择报考方向" class="search_info">
            <el-option
              v-for="item in drectList"
              :key="item.key"
              :label="item.value"
              :value="item.key"
            ></el-option>
          </el-select>
          <!-- <el-input v-model="testDirection" type="text" style="width: 140%;" auto-complete="off" placeholder="请输入报考方向">
          </el-input> -->
        </el-form-item>
      </div>
      <div class="flex_row">
        <div class="reg_title">推荐人：</div> 
        <el-form-item>
          <el-input v-model="reference" type="text" style="width: 140%;" auto-complete="off" placeholder="请输入推荐人（非必填）">
          </el-input>
        </el-form-item>
      </div>
      <el-form-item style="width:100%;justy-content:space-bet">
        <el-button
          size="medium"
          style="width:47%;"
          @click="reset()"
        >
          <span>重 置</span>
        </el-button>
        <el-button
          :loading="loading"
          size="medium"
          type="primary"
          style="width:47%;"
          @click.native.prevent="handleLogin"
        >
          <span v-if="!loading">确 定</span>
          <span v-else>确 定 中...</span>
        </el-button>
      </el-form-item>
    </el-form>
    <!--  底部  -->
    <!-- <div class="el-login-footer">
      <span>Copyright © 2018-2020 ruoyi.vip All Rights Reserved.</span>
    </div> -->
  </div>
</template>

<script>
import { getCodeImg } from "@/api/login";
import Cookies from "js-cookie";
import { encrypt, decrypt } from '@/utils/jsencrypt'
import { studentAdd, getPhoneCode } from "@/api/system/user";

export default {
  name: "Login",
  data() {
    return {
      codeBtn: true,
      last: false,
		  number: '',
      codeUrl: "",
      cookiePassword: "",
      loginForm: {
        username: "",
        password: "",
        confirmPsw: '',
        code: "",
        phone: ""
      },
      loginRules: {
        username: [
          { required: true, trigger: "blur", message: "用户名不能为空" }
        ],
        password: [
          { required: true, trigger: "blur", message: "密码不能为空" }
        ],
      },
      loading: false,
      redirect: undefined,
      username: '',
      sex: '',
      sexList: [
        {key: '0', value: '男'},
        {key: '1', value: '女'},
        {key: '2', value: '未知'}
      ],
      education: '',
      educationList: [
        {key: '1', value: '博士及以上'},
        {key: '2', value: '硕士'},
        {key: '3', value: '本科'},
        {key: '4', value: '专科'},
        {key: '5', value: '高中'},
        {key: '6', value: '其他'}
      ],
      phonenumber: '',
      identificationCard: '',
      work: '',
      testLevel: '',
      levelList:  [
        { key: '1', value: '初级' },
        { key: '2', value: '中级' }, 
        { key: '3', value: '高级' }, 
        { key: '4', value: '技师（暂未开放）' }
      ],
      testDirection: '',
      drectList: [
        { key: '1', value: '监控方向' },
        { key: '2', value: '维保方向' }
      ],
      reference: '',
    };
  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect;
      },
      immediate: true
    }
  },
  created() {
    // this.getCode();
    // this.getCookie();
  },
  methods: {
    reset() {
      this.username = ''
      this.sex = ''
      this.phonenumber = ''
      this.identificationCard = ''
      this.education = ''
      this.work = ''
      this.testLevel = ''
      this.testDirection = ''
      this.reference = ''
    },
    handleLogin() {
      var params = {
        studentName: this.username,
        sex: this.sex,
        phonenumber: this.phonenumber,
        nation: this.nation,
        identificationCard: this.identificationCard,
        education: this.education,
        work: this.work,
        testLevel: this.testLevel,
        testDirection: this.testDirection,
        reference: this.reference,
      }
      var isToken = false
      this.loading = true
      studentAdd(params, isToken).then(res=> {
          this.loading = false
          if (res.code = 200) {
            this.$message({
              type: "success",
              message: res.msg,
            });
            this.$router.push('/login')
          } else {
            this.$message({
              type: "error",
              message: res.msg,
            });
          }
        }
      );
    },
    goback() {
      this.$router.push('/login')
    },
    getmsg() {
      if(this.loginForm.phone==''||this.loginForm.phone==null){
        this.$message.error('请输入手机号')
        return
      }
      let _this = this
      var params = {
        phone: this.loginForm.phone
      }
      getPhoneCode(this.$qs.stringify(params)).then(res => {
        }
      );
    },
    forgetPsw() {
      this.$router.push({ path: "/forgetPsw" });
    },
    getCode() {
      // getCodeImg().then(res => {
      //   this.codeUrl = "data:image/gif;base64," + res.img;
      //   this.loginForm.uuid = res.uuid;
      // });
    },
    // getCookie() {
    //   const username = Cookies.get("username");
    //   const password = Cookies.get("password");
    //   const rememberMe = Cookies.get('rememberMe')
    //   this.loginForm = {
    //     username: username === undefined ? this.loginForm.username : username,
    //     password: password === undefined ? this.loginForm.password : decrypt(password),
    //     rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
    //   };
    // },
    // handleLogin() {
    //   this.$refs.loginForm.validate(valid => {
    //     if (valid) {
    //       this.loading = true;
    //       if (this.loginForm.rememberMe) {
    //         Cookies.set("username", this.loginForm.username, { expires: 30 });
    //         Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
    //         Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
    //       } else {
    //         Cookies.remove("username");
    //         Cookies.remove("password");
    //         Cookies.remove('rememberMe');
    //       }
    //       this.$store.dispatch("Login", this.loginForm).then(() => {
    //         this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
    //       }).catch(() => {
    //         this.loading = false;
    //         this.getCode();
    //       });
    //     }
    //   });
    // }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.login {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  // background-image: url("../assets/images/register_bg.png");
  // background-size: cover;
}
.title {
  margin: 0px auto 30px auto;
  text-align: center;
  color: #409EFF;
  font-size: 22px;
  font-weight: Bold;
  // font-family: MicrosoftYaHei;
}

.login-form {
  border-radius: 6px;
  background: #ffffff;
  width: 480px;
  padding: 25px 48px 5px 48px;
  // .el-input {
  //   height: 48px;
  //   input {
  //     height: 48px;
  //   }
  // }
  .input-icon {
    height: 39px;
    width: 14px;
    margin-left: 2px;
  }
}
.login-tip {
  font-size: 13px;
  text-align: center;
  color: #bfbfbf;
}
.login-code {
  width: 33%;
  height: 38px;
  float: right;
  img {
    cursor: pointer;
    vertical-align: middle;
  }
}
.el-login-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
}
.login-code-img {
  height: 38px;
}
.flex_row {
  display: flex;
  // justify-content: space-between;
  // font-size: 14px;
  // color: #1890ff;
}
.register img{
  width: 550px;
  height: 400px;
  margin-right: 90px;
}
.back {
  font-size: 14px;
  color: #409eef;
  font-weight: bold;
  cursor: pointer;
}
.reg_title {
  font-size: 14px;
  color: #324057;
  margin-right: 16px;
  position: relative;
  top: 10px;
  width: 84px;
}
.code_btn {
  position: absolute;
  top:0;
  left: 170px;
}
</style>
